// pages/zuoyebiao/zuoyebiao.js
var app = getApp();
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    studentid:0,
    page:1,
    zuoye:[],
    user:{},
    gettasks: app.data.url +'/zhongxue/maoapi/gettasks',
    src: app.data.url +"/uploads/zhongxue/kemuss.png",
    zuoyes: [{
        sate: 1,
      kemu:"语",
        name: "张徐琴",
        neirong: "本周语文作业我已经布置下去了，请家长监督孩子及时做完作业，谢谢！",
        date:"2017-08-19",
      }, {
        sate: 1,
        kemu: "数",
        name: "张徐琴",
        neirong: "本周语文作业我已经布置下去了，请家长监督孩子及时做完作业，谢谢！",
        date: "2017-08-19",
      },
      {
        sate: 0,
        kemu: "英",
        name: "张徐琴",
        neirong: "本周语文作业我已经布置下去了，请家长监督孩子及时做完作业，谢谢！",
        date: "2017-08-19 16:40",
      },
    ]
  },

  zuoyexq:function(e){
    console.log(e);
    var id = e.currentTarget.dataset.id;
    // return
   wx.navigateTo({
     url: '/pages/zuoyexq/zuoyexq?id='+id,
   })
 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var id = options.id;
    var user = wx.getStorageSync('user');
    this.setData({studentid:id,user:user})
    this.getData();
  },
  getData:function(){
    var user = wx.getStorageSync('user');
    var id = this.data.studentid;
    var page = this.data.page;
    var that = this;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none',
        duration: app.data.quanbushijian
      })
      return
    }
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: that.data.gettasks,
      data: {token:user.token,id:id,page:page},
      header: {},
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        var data = res.data;
        console.log(data);
        if(data.code==200){
          var zuoye = that.data.zuoye;
          var shuju = data.data;
          if(shuju.length<10){
            that.setData({page:0})
          }else{
            that.setData({page:page+1})
          }
          ea.each(shuju,function(i,v){
            zuoye.push(v);
          })
          that.setData({ zuoye: zuoye})
        }else{
          wx.showToast({
            title: data.msg,
            icon:'none',
            duration: app.data.quanbushijian
          })
        }
      },
      fail: function(res) {},
      complete: function(res) {
        wx.hideLoading()
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.setData({ page: 1, zuoye:[]});
    this.getData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.getData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      path: '/pages/indexfirst/indexfirst',
    }
  }
})